/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlayGamePanel.java
 *
 * Created on Jul 29, 2011, 3:18:33 PM
 */
package deatax.display.gui;

import deatax.mode.GameMode;
import deatax.network.Client;
import deatax.network.Messages;
import deatax.network.Server;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JPanel;

/**
 *
 * @author pson
 */
public class PlayGamePanel extends javax.swing.JPanel {

    /** Creates new form PlayGamePanel */
    public PlayGamePanel() {
        initComponents();
        btnVS.setActionCommand("80");
        btnS.setActionCommand("120");
        btnM.setActionCommand("200");
        btnL.setActionCommand("300");
        btnVL.setActionCommand("400");
        descriptionField.setText(Client.getData().getMode("Elimination").getDesc());
    }

    public void addPlayListener(ActionListener listener) {
        btnPlay.addActionListener(listener);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnGroupMapSize = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cbGameMode = new javax.swing.JComboBox();
        cbLandmass = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        btnS = new javax.swing.JRadioButton();
        btnVL = new javax.swing.JRadioButton();
        btnVS = new javax.swing.JRadioButton();
        btnL = new javax.swing.JRadioButton();
        btnM = new javax.swing.JRadioButton();
        btnPlay = new javax.swing.JButton();
        pnlGameMode = new javax.swing.JPanel();
        scrollGameMode = new javax.swing.JScrollPane();
        descriptionField = new javax.swing.JTextPane();

        jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD, jLabel1.getFont().getSize()+9));
        jLabel1.setText("Setup");

        jLabel2.setText("Landmass Type");

        jLabel4.setText("Game Mode");

        jLabel3.setText("Map Size");

        cbGameMode.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Elimination", "Domination", "Civilisation" }));
        cbGameMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbGameModeActionPerformed(evt);
            }
        });

        cbLandmass.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pangaea", "Continental", "Waterworld", "Mountain Range" }));

        btnGroupMapSize.add(btnS);
        btnS.setSelected(true);
        btnS.setText("Small");

        btnGroupMapSize.add(btnVL);
        btnVL.setText("Very Large");

        btnGroupMapSize.add(btnVS);
        btnVS.setText("Very Small");

        btnGroupMapSize.add(btnL);
        btnL.setText("Large");

        btnGroupMapSize.add(btnM);
        btnM.setText("Medium");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnVS)
                    .addComponent(btnS)
                    .addComponent(btnM)
                    .addComponent(btnL)
                    .addComponent(btnVL))
                .addContainerGap(98, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(btnVS)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnS)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnM)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnL)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnVL)
                .addContainerGap())
        );

        btnPlay.setFont(btnPlay.getFont().deriveFont(btnPlay.getFont().getStyle() | java.awt.Font.BOLD, btnPlay.getFont().getSize()+5));
        btnPlay.setText("PLAY");
        btnPlay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPlayActionPerformed(evt);
            }
        });

        pnlGameMode.setLayout(new javax.swing.BoxLayout(pnlGameMode, javax.swing.BoxLayout.Y_AXIS));

        scrollGameMode.setBorder(null);
        scrollGameMode.setOpaque(false);

        descriptionField.setBorder(null);
        descriptionField.setEditable(false);
        descriptionField.setOpaque(false);
        scrollGameMode.setViewportView(descriptionField);

        pnlGameMode.add(scrollGameMode);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlGameMode, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cbLandmass, javax.swing.GroupLayout.Alignment.TRAILING, 0, 181, Short.MAX_VALUE)
                            .addComponent(cbGameMode, 0, 181, Short.MAX_VALUE)))
                    .addComponent(btnPlay, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cbLandmass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cbGameMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlGameMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 154, Short.MAX_VALUE)
                .addComponent(btnPlay)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cbGameModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbGameModeActionPerformed
        pnlGameMode.removeAll();
        pnlGameMode.add(scrollGameMode);
        GameMode gm = Client.getData().getMode(cbGameMode.getSelectedItem().toString());
        descriptionField.setText(gm.getDesc());
        for (int i = 0; i < gm.getReqs().length; ++i) {
            JLabeledTextField jtf = new JLabeledTextField();
            jtf.setEmptyText(gm.getReqs()[i]);
            jtf.setText(gm.getReqv()[i]);
            pnlGameMode.add(jtf);
        }
        //pnlGameMode.add(new JPanel());
        validate();
        repaint();
    }//GEN-LAST:event_cbGameModeActionPerformed

    private void btnPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPlayActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnPlayActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btnGroupMapSize;
    private javax.swing.JRadioButton btnL;
    private javax.swing.JRadioButton btnM;
    private javax.swing.JButton btnPlay;
    private javax.swing.JRadioButton btnS;
    private javax.swing.JRadioButton btnVL;
    private javax.swing.JRadioButton btnVS;
    private javax.swing.JComboBox cbGameMode;
    private javax.swing.JComboBox cbLandmass;
    private javax.swing.JTextPane descriptionField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel pnlGameMode;
    private javax.swing.JScrollPane scrollGameMode;
    // End of variables declaration//GEN-END:variables

    void assignParams() {
        Server.get().sendMessages(Messages.MAP_DEFINE, 
                new String[]{String.valueOf(new Random().nextInt()), 
                    cbLandmass.getSelectedItem().toString(), 
                    btnGroupMapSize.getSelection().getActionCommand(), 
                    cbGameMode.getSelectedItem().toString()});
    }

    
}
